/**
 * @Author: zouzhirui 804250471@qq.com
 * @Date: 2024-10-24 16:50:20
 * @LastEditors: zouzhirui 804250471@qq.com
 * @LastEditTime: 2024-10-24 16:50:27
 * @FilePath: lib/http.js
 * @Description: 这是默认设置,可以在设置》工具》File Description中进行配置
 */

// lib/http.js

// 通过 axios 处理请求
const axios = require('axios')
const {orgName, accessToken} = require("../const");

axios.interceptors.response.use(res => {
    return res.data;
})

/**
 * 获取模板列表
 * @returns Promise
 */
async function getRepoList() {

    try {
        return axios.get(`https://gitee.com/api/v5/orgs/${orgName}/repos`, {headers: {'Authorization': `token ${accessToken}`}})
    } catch (error) {
        console.error('Error fetching repositories:', error);
    }


    // return axios.get('https://api.github.com/orgs/frontend-system/repos')
}

/**
 * 获取版本信息
 * @param {string} repo 模板名称
 * @returns Promise
 */
async function  getTagList(repo) {
    return axios.get(`https://gitee.com/api/v5/orgs/frontend-system/${repo}/tags`, {
        headers: {
            'Authorization': `token ${accessToken}`
        }
    })
    // return axios.get(`https://api.github.com/repos/frontend-system/${repo}/tags`)
}

module.exports = {
    getRepoList,
    getTagList
}

